<?php
add_action( 'admin_footer', 'invisible_select_cp_type' );

function invisible_select_cp_type() {
?>
<script type="text/javascript">

jQuery(document).ready(function($) {
    
    // AUTO SELECT STORE BY STORE ID - FOR ADD NEW STORE
    function getUrlVars()
    {
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for(var i = 0; i < hashes.length; i++)
        {
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }
        return vars;
    }
    var sl_store = "#store_coupon_metadata";    
    if($(sl_store).length > 0)
    {
        var st_id = getUrlVars()['store_id'];
        if(st_id)
            $(sl_store).val(st_id);
    }
    
    /**
     * TOGGLE COUPON TYPE
     */
    // check if object exitsted
    var sl = "#coupon_type_metadata";
    var input_cp_code = "#coupon_code_metadata";
    if($(sl).length > 0)
    {
        function dis()
        {
            $(input_cp_code).attr('disabled','disabled');
            $(input_cp_code).css('background-color','whitesmoke');
        }
        function en()
        {
            $(input_cp_code).removeAttr('disabled');
            $(input_cp_code).css('background-color','');
        }
        
        if($(sl).val() == 'promotion')
            dis();
        else
            en();
        $(sl).change(function(){
            if($(this).val() == 'promotion')
                dis();
            else
                en();    
        })
    }
    
});

</script>
<?php
}
?>
